/**
 * Copyright (C) 2008 GeoScheduler Team, as stated on <http://www.geoscheduler.org/authors>.
 * 
 * This file is part of GeoScheduler.
 * 
 * GeoScheduler is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GeoScheduler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with GeoScheduler. If not, see <http://www.gnu.org/licenses/>.
 */

package org.geoscheduler.commons.collections;

import java.util.Iterator;

/**
 * 
 * <h2>TransformingIterator</h2>
 * <p>
 * Typesafe decorator providing callback method {{@link #next(Object)} to
 * transform object instance before returned by {@link Iterator}
 * </p>
 * <p>
 * Class is intended to be extended as anonymous inner class or in place
 * specific implementation.
 * </p>
 * 
 * @see TransformingIterator
 * @author LKo (Lukas.Kolisko@Geoscheduler.Org)
 * 
 */
public abstract class TransformingIterator<F, T> implements Iterator<T> {

	private final Iterator<F> inner;

	public TransformingIterator(Iterator<F> inner) {
		this.inner = inner;
	}

	public boolean hasNext() {
		return inner.hasNext();
	}

	public T next() {
		return next(inner.next());
	}

	/**
	 * Callback method, that implements transformation from {@param origin} to
	 * final type.
	 */
	protected abstract T next(F origin);

	public void remove() {
		throw new UnsupportedOperationException("iteration is readonly");
	}
}
